//
//  EvaluateTopCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2018/1/8.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "EvaluateTopCell.h"

@interface EvaluateTopCell ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;
@property (weak, nonatomic) IBOutlet UILabel *goods_nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
@property (weak, nonatomic) IBOutlet UIButton *middelBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UIImageView *leftImageVeiw;

@end

@implementation EvaluateTopCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.bottomMargin.constant = 0;
    
    self.leftBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.middelBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.rightBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
    
    self.leftBtn.titleLabel.font = MYFONT(16);
    self.middelBtn.titleLabel.font = MYFONT(16);
    self.rightBtn.titleLabel.font = MYFONT(16);
    
//    self.leftBtn.titleLabel.backgroundColor = [UIColor redColor];
//    self.leftBtn.imageView.backgroundColor = [UIColor blueColor];

    self.goods_nameLabel.font = MYFONT(16);
    
    self.goods_nameLabel.textColor = darkGray;
    
    self.leftBtn.imageEdgeInsets = UIEdgeInsetsMake(10, 0, 10, 0);
    self.middelBtn.imageEdgeInsets = UIEdgeInsetsMake(10, 0, 10, 0);
    self.rightBtn.imageEdgeInsets = UIEdgeInsetsMake(10, 0, 10, 0);
    
    
    CGFloat imgW = (self.leftImageVeiw.size.width - 22) * 0.5 - 16;
    self.leftBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -imgW, 0, 0);
    self.middelBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -imgW, 0, 0);
    self.rightBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -imgW, 0, 0);

    
    self.priceLabel.font = MYFONT(19);
    
    self.priceLabel.textColor = [UIColor redColor];
    
    [self.leftBtn setTitleColor:darkGray forState:UIControlStateNormal];
    [self.leftBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
    [self.middelBtn setTitleColor:darkGray forState:UIControlStateNormal];
    [self.middelBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
    [self.rightBtn setTitleColor:darkGray forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
    

    // Initialization code
}

- (void)setModel:(GoodEvaluateParm *)model{
    _model = model;
    
    [self.leftImageVeiw sd_setImageWithURL:[NSURL URLWithString:_model.imgUrl] placeholderImage:nil];

    self.priceLabel.text = [NSString stringWithFormat:@"%@P",_model.price];
    
    self.goods_nameLabel.text = _model.good_name;
    
    if ([_model.explain_type isEqualToString:@"1"]) {
        self.leftBtn.selected = YES;
        self.middelBtn.selected = NO;
        self.rightBtn.selected = NO;
    } else if ([_model.explain_type isEqualToString:@"1"]) {
        self.leftBtn.selected = NO;

        self.middelBtn.selected = YES;
        self.rightBtn.selected = NO;
    }else{
        self.leftBtn.selected = NO;

        self.middelBtn.selected = NO;
        self.rightBtn.selected = YES;
        
    }
    
    
    
}

- (IBAction)leftBtnDidTap:(UIButton *)sender {
    
    if (sender.selected) {
        return;
    }
    
    sender.selected = !sender.selected;
    self.model.explain_type = @"1";
    
        self.middelBtn.selected = NO;
        self.rightBtn.selected = NO;

}


- (IBAction)middleBtnDidTap:(UIButton *)sender {
    if (sender.selected) {
        return;
    }
    
    sender.selected = !sender.selected;
    self.model.explain_type = @"2";
        self.leftBtn.selected = NO;
        self.rightBtn.selected = NO;
    
}


- (IBAction)rightBtnDidTap:(UIButton *)sender {
    if (sender.selected) {
        return;
    }
    
    sender.selected = !sender.selected;
    self.model.explain_type = @"3";
        self.middelBtn.selected = NO;
        self.leftBtn.selected = NO;
   
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
